#! /usr/bin/python
# Filename: backup_ver3.py

import os
import time

sourcelist = ['/home/F1213366/python','/home/F1213366/work/code'];
target_dir = '/home/F1213366/backup/';
delimiter = ' ';
today = target_dir + time.strftime('%Y%m%d');
now = time.strftime('%H%M%S');

comment = raw_input('Enter a comment at the end:');
if len(comment) ==0:
	target = today + os.sep + now + '.tar.gz';
else:
	target = today + os.sep + now + '_'  + comment.replace(' ','_') + '.tar.gz';

if not os.path.exists(today):
	print 'Creating directory',today,'...';
	os.mkdir(today);

tar_cmd = "tar -cf '%s' %s" % (target, delimiter.join(sourcelist));

print 'tar_cmd:',tar_cmd;

if os.system(tar_cmd) == 0:
	print 'Successful backup to',target;
else:
	print 'Backup FAILED!';
